package cn.wolfcode.controller;


import cn.wolfcode.domain.Comment;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.MessageBoard;
import cn.wolfcode.qo.MessageBoardQuery;
import cn.wolfcode.service.ICommentService;
import cn.wolfcode.service.IMessageBoardService;
import cn.wolfcode.result.JsonResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/messageBoard")
public class MessageBoardController {
    @Autowired
    private IMessageBoardService messageBoardService;
    @Autowired
    private ICommentService commentService;
    @RequestMapping("/query")
    public Object query(MessageBoardQuery qo){
        IPage<MessageBoard> page = messageBoardService.queryPage(qo);
        return new JsonResult(true,page);
    }
    @RequestMapping("/saveOrUpDate")
    public Object saveOrUpDate(MessageBoard messageBoard){
        messageBoardService.saveMessage(messageBoard);
        return new JsonResult(true,null);
    }
    @RequestMapping("/delete")
    public Object delete(Long id){
        return new JsonResult();
    }
    @RequestMapping("/detail")
    public Object detail(Long id){
        MessageBoard messageBoard = messageBoardService.getById(id);
        List<Comment> comments = commentService.getByMessageBoardId(id);
        messageBoard.setComments(comments);
        return new JsonResult(true,messageBoard);
    }
}
